﻿using System;
using System.Threading.Tasks;
using K9Admin.Remoting;
using K9Nano.RemoteClient;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace ClientTest
{
    class Program
    {
        static async Task Main(string[] args)
        {
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

            var services = new ServiceCollection()
                .AddLogging(b => b.AddConsole());

            services.AddRemoteClient<UserService.UserServiceClient>(options =>
            {
                options.MaxPool = 2;
                options.Uri = "http://localhost:81";
            });

            var serviceProvider = services.BuildServiceProvider(); ;

            var request = new UserCreateRequest
            {
                Name = "邓胜爽2",
                Gender = 1,
                //Password = "123456",
                Phone = "13408389841",
                //Avatar = "http://dd.com",
                //Email = "yangch_ts@qq.com"
            };
            request.Roles.Add("jubaoke.agent11");

           var client = serviceProvider.GetRequiredService<UserService.UserServiceClient>();

            try
            {
                var id = await client.CreateAsync(request);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
